Telegram Group & Telegram Channel
Checks if a string is an anagram of another string (case-insensitive, ignores spaces, punctuation and special characters).

Use isalnum() to filter out non-alphanumeric characters, lower() to transform each character to lowercase.

Use collections.Counter to count the resulting characters for each string and compare the results.

Code
:

from collections import Counter

def is_anagram(s1, s2):
return Counter(
c.lower() for c in s1 if c.isalnum()
) == Counter(
c.lower() for c in s2 if c.isalnum()
)

EXAMPLE

is_anagram("#anagram", "Nag a ram!")

Output:
True

Share and Support
@Python_Codes



tg-me.com/python_codes/150
Create:
Last Update:

Checks if a string is an anagram of another string (case-insensitive, ignores spaces, punctuation and special characters).

Use isalnum() to filter out non-alphanumeric characters, lower() to transform each character to lowercase.

Use collections.Counter to count the resulting characters for each string and compare the results.

Code
:

from collections import Counter

def is_anagram(s1, s2):
return Counter(
c.lower() for c in s1 if c.isalnum()
) == Counter(
c.lower() for c in s2 if c.isalnum()
)

EXAMPLE

is_anagram("#anagram", "Nag a ram!")

Output:
True

Share and Support
@Python_Codes

BY Python Codes


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/python_codes/150

View MORE
Open in Telegram


Python Codes Telegram | DID YOU KNOW?

Date: |

The Singapore stock market has alternated between positive and negative finishes through the last five trading days since the end of the two-day winning streak in which it had added more than a dozen points or 0.4 percent. The Straits Times Index now sits just above the 3,060-point plateau and it's likely to see a narrow trading range on Monday.

What is Telegram Possible Future Strategies?

Cryptoassets enthusiasts use this application for their trade activities, and they may make donations for this cause.If somehow Telegram do run out of money to sustain themselves they will probably introduce some features that will not hinder the rudimentary principle of Telegram but provide users with enhanced and enriched experience. This could be similar to features where characters can be customized in a game which directly do not affect the in-game strategies but add to the experience.

Python Codes from ms


Telegram Python Codes
FROM USA